package com.zjy.software.day13;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapTest {
    public static void main(String[] args)
    {
        Map<String,String> map=new HashMap<>();
        map.put("111","aaaa");
        map.put("222","bbbb");
        map.put("333","cccc");
        //如果加入同样的key,那么键重复，值会覆盖
        map.put("333","dddd");

        //key可以为null，value也可以为null
        map.put(null,"eeee");
        map.put(null,null);

        System.out.println("map = " + map);

        System.out.println("map.get(\"111\") = " + map.get("111"));

        System.out.println("map.containsKey(\"1111\") = " + map.containsKey("1111"));
        System.out.println("map.size() = " + map.size());

        map.remove("222");
        System.out.println("map = " + map);

        //正常情况下,遍历map需要先拿到key的集合,然后遍历key,从而得到value
        Set<String> keys = map.keySet();
        for (String key : keys) {
            String value = map.get(key);
            System.out.println("key = " + key + ", value = " + value);

        }


    }
}
